def spam():
    # global eggs
    print(eggs)  # 编译时，看到下一句eggs赋值，认为eggs为局部变量
                 # 但print()时，eggs并未完成赋值，故报错
    eggs = 'spam local'

eggs = 'global'
spam()
